package com.yanqu.road.server.cmd.activity.suitang;

import com.yanqu.road.entity.activity.suitang.config.SuiTangConfigSync;
import com.yanqu.road.entity.activity.tongbing.config.TongBingConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.TongBingProto;
import com.yanqu.road.pb.activity.suitang.SuiTang;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.suitang.SuiTangMgr;
import com.yanqu.road.server.manger.activity.tongbing.TongBingMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_SUI_TANG_CITY_WAR_REPORT, desc = "")
public class SuiTangCityWarReportCmd extends AbstractCommand {

    private SuiTang.SuiTangCityWarReportReqMsg reqMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = SuiTang.SuiTangCityWarReportReqMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        SuiTangConfigSync config = SuiTangMgr.getConfig();
        if (config == null || !ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        if (!config.isRequestTime()) {
            SuiTang.SuiTangCityWarReportRespMsg.Builder respMsg = SuiTang.SuiTangCityWarReportRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_SUI_TANG_CITY_WAR_REPORT, respMsg);
            return;
        }

        SuiTang.CrossSuiTangCityWarReportReqMsg.Builder builder = SuiTang.CrossSuiTangCityWarReportReqMsg.newBuilder();
        builder.setActivityId(config.getActivityInfo().getActivityId());
        builder.setReq(reqMsg);
        player.sendUnionActivityGroupPacket(CrossProtocol.C2_SUI_TANG_CITY_WAR_REPORT, builder, config.getActivityInfo().getActivityId());
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret == 0) {
            return;
        }

        SuiTang.SuiTangCityWarReportRespMsg.Builder respMsg = SuiTang.SuiTangCityWarReportRespMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(ClientProtocol.U_SUI_TANG_CITY_WAR_REPORT, respMsg);
    }
}
